﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.zaofan.bean.Lable"%>
<%@page import="com.zaofan.cache.CacheManage"%>
<%@page import="com.zaofan.constant.LableConstant"%>
<%@page import="com.zaofan.bean.Admin"%>
<%@page import="com.zaofan.bean.AdminType"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	String contextPath = request.getContextPath();
	Admin admin = (Admin)session.getAttribute("admin");
	if(admin == null){
		response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
		return;
		}
	if(admin.getType() != AdminType.admin.ordinal() &&  admin.getType() != 4){
		response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
		return;
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>明日送货订单</title>
<link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet" />
<link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome.min.css" />
<!--[if IE 7]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css" />
<![endif]-->
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-skins.min.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css" />
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
<!--[if lt IE 9]>
	<script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/chosen.css" />
<script type="text/javascript">  
       var contextPath='<%=contextPath%>';
</script>
</head>
<body style="background-color: #fff;">
						<%
								application.setAttribute("special", CacheManage.specialShop);
								pageContext.setAttribute("admin", admin);
								application.setAttribute("expressType", CacheManage.lables.get(LableConstant.lable_express_type));
							%>
	<div class="page-content">
		<div id="adEditBox"
			 style="display: none; z-index: 99; width: 600px; position: fixed; left: 15%; top: 5%; border: 1px solid #ccc; border-radius: 4px !important;">
			<div class="arrow"></div>
			<div class="popover-inner" style="">
				<h3 class="popover-title" >订单编辑</h3>
				<div class="popover-content"  style="background-color: #F5F5F5;">
					<form class="form-horizontal" style="padding-top: 10px;"
						  method="get" id="adForm" enctype="multipart/form-data">
						<input type="hidden" id="id" name="id" value="" />
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">送货日期：</label>
							<div class="col-sm-9">
								<input class="form-control" name="sendDate" id="sendDate"/>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>
						<div class="form-group">
							<label  class="col-sm-2 control-label">送货时间</label>
							<div class="col-sm-9">
								<input class="form-control" name="sendTime" id="sendTime"/>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>
						<div class="form-group">
							<label  class="col-sm-2 control-label">收货人</label>
							<div class="col-sm-9">
								<input class="form-control" name="consignee" id="consignee"/>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>

						<div class="form-group">
							<label  class="col-sm-2 control-label">收货大楼：</label>
							<div class="col-sm-9">
								<input class="form-control" name="builderName" id="builderName"></input>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>

						<div class="form-group">
							<label for="" class="col-sm-2 control-label">收货楼层：</label>
							<div class="col-sm-9">
								<input class="form-control" name="floorNo" id="floorNo"></input>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>

						<div class="form-group">
							<label for="" class="col-sm-2 control-label">收货人电话：</label>
							<div class="col-sm-9">
								<input class="form-control" name="userMobile" id="userMobile"></input>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>
					</form>
				</div>
				<div class="popover-footer"
					 style="background-color: #F5F5F5; overflow: hidden; text-align: center;">
					<button type="button" class="btn btn-primary"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="cancel">
						<i class="icon-ok"></i>取消
					</button>
					<button type="button" class="btn btn-danger"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="save">
						<i class="icon-edit"></i>保存
					</button>

				</div>
			</div>
		</div>


		<div class="row" style="height: 100%">
			<div class="col-xs-12">
				<div class="panel panel-default">
				  <div class="panel-heading">订单打印</div>
				  <div class="panel-body">
				  	<%-- 	<a href="<%=contextPath%>/order?action=exportTomorrowSendUserPhone" >导出明日送餐用户号码</a>
				  		<a href="<%=contextPath%>/order?action=exportTomorrowListProduct" >打印生产单</a> --%>
				  </div>
				</div>
			
				<div class="panel panel-default">
				  <div class="panel-heading">订单查找</div>
				  <div class="panel-body">
				  		<form class="form-inline">
				  				<label for="key">城市:</label>
				  				<select id="citys" style="width:150px;" >
				  					
				  				</select>&nbsp;&nbsp;
				  				<label for="key">区域:</label>
				  				<select id="areas" style="width:150px;" >
				  					
				  				</select>&nbsp;&nbsp;
				  				<label for="key">大楼:</label>
				  				<select id="builders" style="width:150px;" >
				  					
				  				</select>&nbsp;&nbsp;
				  				<label for="key">商铺:</label>
				  				<select id="shops" style="width:150px;" >
				  						<option value="-1" selected="selected">全部</option>
				  						<c:forEach items="${special }" var="e">
											<c:if test="${e.cityId == admin.getCityId()}"><option value="${e.id }" >${e.shopName }</option></c:if>
										</c:forEach>
				  				</select>&nbsp;&nbsp;
								<input type="hidden" value="" id="builderId"  />
								<input type="hidden" value="" id="shopId"  />
								<input type="hidden" value="" id="areaId"  />
								<input type="hidden" value="" id="property"  /><input type="hidden" value="" id="accountMobile"  />
								<input type="hidden" value="" id="key"  />
								<label for="key">号码：</label>
								<input id="mobile" class="form-control" value="" style="width:100px;" />&nbsp;&nbsp;<br/><br/>
								<label for="key">收货人号码：</label>
								<input id="phone" class="form-control" value="" style="width:100px;" />&nbsp;&nbsp;<br/><br/>
								<button type="button" class="btn btn-primary btn-sm" id="find">查找</button>
								<button type="button" class="btn btn-primary btn-sm" id="print">打印</button>
							<!-- 	<button type="button" class="btn btn-primary btn-sm" id="printNote">打印贴条</button> -->
						</form>
				  </div>
				</div>
			</div>
			<div class="col-xs-12">
			<style>
				.table-responsive table th tr{text-align: center;}
			</style>
				<div class="table-responsive">
					
					<input type="hidden" value="1" id="start" />
					<table id="sample-table-2"
						class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>
								<label><input type="checkbox" class="ace checkAll"><span class="lbl"></span></label>
								</th>
								<th style="text-align: center;">订单号</th>
								<th style="text-align: center;">用户</th>
								<th style="text-align: center;">下单时间</th>
								<th style="text-align: center;">送餐时间</th>
								<th style="text-align: center;">价格</th>
								<th style="text-align: center;">下单平台</th>
								<th style="text-align: center;">城市</th>
								<th style="text-align: center;">收货信息</th>
								<th style="text-align: center;">状态</th>
								<th style="text-align: center;">支付状态</th>
								<th style="text-align: center;">支付方式</th>
								<th style="text-align: center;">操作</th>
							</tr>
						</thead>
						<tbody id="data-list"  style="text-align: center;">
						</tbody>
					</table>
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
		<div class="row">
			<div class="col-sm-6">
				<div id="sample-table-2_info" class="dataTables_info">
					当前    <span id="current">  </span> 到  <span id="page"></span> 总共 <span
						id="total"></span> 条
				</div>
			</div>
			<div class="col-sm-6">
				<div class="dataTables_paginate paging_bootstrap">
					<ul class="pagination pagination-sm" id="page-list">
					</ul>
				</div>
			</div>
		</div>
	</div>
	<style>
		#detailsBox{border:1px solid #999;border-bottom:none;}
		#detailsBox thead tr th{width:20%;padding:10px;}
		#detailsBox thead tr{border-bottom:1px solid #999;}
		#detail-list tr{border-bottom:1px solid #999;}
		
	</style>
	<div id="detailsBox" style="width: 900px;position: absolute;display:none; ">
		<table id="sample-table-2"
			class=""  style="background-color:#f5f5f5;width:100%">
			<thead  style="background-color:#f5f5f5;width:100%">
				<tr>
					<th style="text-align: center;">产品名</th>
					<th style="text-align: center;">产品图片</th>
					<th style="text-align: center;">产品价格</th>
					<th style="text-align: center;">产品数量</th>
					<th style="text-align: center;">商铺信息</th>
				</tr>
			</thead>
			<tbody id="detail-list" style="text-align: center;background-color:#f5f5f5">
			</tbody>
		</table>
	</div>
	
	<div id="loading"
		style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
		<img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
			width="32" height="32" />
	</div>
	
	<div class="popover"
		style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
		<div class="arrow"></div>
		<div class="popover-inner">
			<h3 class="popover-title">操作提示</h3>
			<div class="popover-content" id="popover-content">
				<p>操作成功</p>
			</div>
		</div>
	</div>
	
	
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
								+ "<"+"script>");
	</script>
	
	<!--[if IE]>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
		</script>
	<![endif]-->
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"script>");
	</script>
	<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

	<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
	<![endif]-->
	<script src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
	<script src="<%=contextPath%>/admin/js/common.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-datepicker.min.js"></script>
	
	
	<script type="text/javascript">
	var time = null;
	$.ajax({
		url : contextPath + '/city',
		type : "POST",
		dataType : 'json',
		data : {
			action : 'list',
			order:' by sort asc'
		},
		success : function(rs, textStatus, jqXHR) {
			if (rs.success) {
				var data = rs.data;
				var options = "";
				for(var i = 0 ; i < data.length ; i++){
					options += '<option value="'+data[i].id+ '">' + data[i].cityName + '</option>';
				}
				$("#citys").append(options);
				$.ajax({
					url : contextPath + '/area',
					type : "POST",
					dataType : 'json',
					data : {
						action : 'list',
						cityId:$("#citys").val(),
						order:' by sort asc'
					},
					success : function(rs, textStatus, jqXHR) {
						if (rs.success) {
							var data = rs.data;
							var options = '<option value="-1" selected="selected">全部</option>';
							for(var i = 0 ; i < data.length ; i++){
								options += '<option value="'+data[i].id+ '">' + data[i].areaName + '</option>';
							}
							$("#areas").empty();
							$("#areas").append(options);
						} else {
							showMessage("获取数据失败,请稍后再试");
						}
						$("#loading").hide();
					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
				});
			} else {
				showMessage("获取数据失败,请稍后再试");
			}
			$("#loading").hide();

		},
		error : function() {
			$("#loading").hide();
			showMessage("请稍后再试");
		}
		});
	
		
	$("#citys").change(function(){
		var val = $(this).val();
		if(val != -1){
			$.ajax({
				url : contextPath + '/area',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'list',
					cityId:val,
					order:' by sort asc'
				},
				success : function(rs, textStatus, jqXHR) {
					if (rs.success) {
						var data = rs.data;
						var options = '<option value="-1" selected="selected">全部</option>';
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value="'+data[i].id+ '">' + data[i].areaName + '</option>';
						}
						$("#areas").empty();
						$("#areas").append(options);
					} else {
						showMessage("获取数据失败,请稍后再试");
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
		}
	});
	
	$("#areas").change(function(){
		
		var val = $(this).val();
		$("#areaId").val(val);
		if(val != -1){
			$.ajax({
				url : contextPath + '/builder',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'list',
					areaId:val,
					cityId:$("#citys").val(),
					order:' by sort asc'
				},
				success : function(rs, textStatus, jqXHR) {
					if (rs.success) {
						var data = rs.data;
						var options = '<option value="-1" selected="selected">全部</option>';
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value="'+data[i].id+ '">' + data[i].builderName + '</option>';
						}
						$("#builders").empty();
						$(".shopother").remove();
						$("#builders").append(options);
						getData(1);
					} else {
						showMessage("获取数据失败,请稍后再试");
					}
					$("#loading").hide();

				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
		}
		
	});
	
	
	$("#builders").change(function(){
		var val = $(this).val();
		$("#builderId").val(val);
		getData(1);
		if(val != -1){
			$.ajax({
				url : contextPath + '/shop',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'open',
					builderId:val
				},
				success : function(rs, textStatus, jqXHR) {
					if (rs.success) {
						var data = rs.data;
						var options="";
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value="'+data[i].id+ '" class="shopother">' + data[i].shopName + '</option>';
						}
						$(".shopother").remove();
						$("#shops").append(options);
						
					} else {
						showMessage("获取数据失败,请稍后再试");
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
			}
		});
	
	$("#shops").change(function(){
		$("#shopId").val($(this).val());
		getData(1);
	});
	

	
		$(function(){
				init();
		});
		function init() {
			setTimeout(getData(1), 1000);
		}

		function getData(start) {
			var property = "";
			if($("#citys").val() == -1 || $("#citys").val() == ""|| $("#citys").val() == null){
				property = "";
			}else{
				property = "cityId=" + $("#citys").val();
			}
			if($("#areaId").val() != -1 && $("#areaId").val() != ""){
				if(property == ""){
					property = "areaId=" + $("#areaId").val();
				} else {
					property = "&areaId=" + $("#areaId").val();
				}
			}
			if($("#builderId").val() != -1 && $("#builderId").val() != ""){
				if(property == ""){
					property = "builderId=" + $("#builderId").val();
				}else{
					property += "&builderId=" + $("#builderId").val();
				}
			}
			if($("#shopId").val() != -1 && $("#shopId").val() != ""){
				if(property == ""){
					property = "shopId=" + $("#shopId").val();
				}else{
					property += "&shopId=" + $("#shopId").val();
				}
			}
			if($("#accountMobile").val() != ""){
				if(property == ""){
					property = "accountMobile=" + $("#accountMobile").val();
				}else{
					property += "&accountMobile=" + $("#accountMobile").val();
				}
			}
			if($("#phone").val() != ""){
				if(property == ""){
					property = "userMobile=" + $("#phone").val();
				}else{
					property += "&userMobile=" + $("#phone").val();
				}
			}
			$("#loading").show();
				$.ajax({
					url : contextPath + '/order' + (property == "" ? "" : "?" + property),
					type : "POST",
					dataType : 'json',
					data : {
						action : 'tomorrow_list',
						begin : (start - 1) * 20,
						end : 20,
						order:' by orderTime desc'
					},
					success : function(rs, textStatus, jqXHR) {
						if (rs.success) {

							var data = rs.data;
							var total = rs.total;
							var cityId = rs.cityId;
							var dataList = $("#data-list");
							dataList.empty();
							$("#total").text(total);
							$("#current").text((start - 1) * 20 + 1);
							if (data.length > 0) {
								$("#page").text(
										(start - 1) * 20 + data.length);
								parseData(data, total, start,cityId);
							} else {
								showMessage("无数据");
							}
						} else {
							showMessage("获取数据失败,请稍后再试");
						}
						$("#loading").hide();

					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
			});
		}

	Date.prototype.Format = function (fmt) { //author: meizz
		var o = {
			"M+": this.getMonth() + 1, //月份
			"d+": this.getDate(), //日
			"h+": this.getHours(), //小时
			"m+": this.getMinutes(), //分
			"s+": this.getSeconds(), //秒
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度
			"S": this.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	}




		function parseData(data, total, start,cityId) {
			var dataList = $("#data-list");
			var tr = "";

			for (var i = 0; i < data.length; i++) {
				if(cityId==1){

					//获得当前时间
					var today = new Date();
					var nowyear = today.getFullYear();
					var nowmonth = today.getMonth();
					var nowday = today.getDate();


					//设置时间为今天
					var orderTime =new Date(data[i].orderTime);
					orderTime.setFullYear(nowyear);
					orderTime.setMonth(nowmonth);
					orderTime.setDate(nowday);
					orderTime= new Date(orderTime).Format("yyyy-MM-dd hh:mm:ss");
					data[i].orderTime=orderTime;


					var tomorrow = new Date();
				    tomorrow.setTime(tomorrow.getTime()+1000*60*60*24);


					var sendDate =new Date(data[i].sendDate);
					sendDate.setFullYear(tomorrow.getFullYear());
					sendDate.setMonth(tomorrow.getMonth());
					sendDate.setDate(tomorrow.getDate());
					sendDate= new Date(sendDate).Format("yyyy-MM-dd");
					data[i].sendDate=sendDate;
				}


				tr += '<tr>';
				tr += '<td><label><input type="checkbox" class="ace items" value="'+data[i].id+'"><span class="lbl"></span></label><input type="hidden" value="'+data[i].id+'" /></td>';
				tr += '<td><a href="javascript:void(0)"  class="showDetai" orderId='+data[i].id+' detailInfo="">'+data[i].orderNo+'</a></td>';
				tr += '<td>'+data[i].accountMobile+'</td>';
				tr += '<td>'+data[i].orderTime+'</td>';
				tr += '<td>'+data[i].sendDate + '<br/>'+data[i].sendTime+'</td>';
				tr += '<td>总价:'+data[i].totalPrice+'<br/>支付价格:'+data[i].payPrice+'<br/>优惠价格:'+data[i].freePrice+'</td>';
				tr += '<td>'+data[i].platform+'</td>';
				tr += '<td>'+data[i].cityName+'</td>';
				tr += '<td>收货人:'+data[i].consignee+'<br/>大楼:'+data[i].builderName+'<br/>楼层:'+data[i].floorNo+'<br/>电话：'+data[i].userMobile+'</td>';
				if(data[i].state == 0){
					tr += '<td>未付款</td>';
				}else if(data[i].state == 1){
					tr += '<td>已付款</td>';
				}else if(data[i].state == 2){
					tr += '<td>已评论</td>';
				}
				tr += '<td>'+data[i].payType+'</td>';
				if(data[i].payState == 0){
					tr += '<td>未付款</td>';
				}else if(data[i].payState == 1){
					tr += '<td>支付确认</td>';
				}else if(data[i].payState == 2){
					tr += '<td>支付</td>';
				}else if(data[i].payState == 3){
					tr += '<td>归档</td>';
				}else if(data[i].payState ==4){
					tr += '<td>已退款</td>';
				}
				tr += '<td><input type="hidden" value="'+data[i].id+'" class="rankId"/>' +
						'<a target="_blank" href="'+contextPath + '/order?action=print_order&orderId=' + data[i].id +'" >打印</a>' +
						'<a onclick= "editorder('+data[i].id+')">编辑</a>' +
						'<a onclick= "backorder('+data[i].id+')">退款</a>' +
						'</td>';
				tr += '</tr>';
			}
			dataList.append(tr);
			
			$(".showDetai").hover(function(event){
				clearTimeout(time); 
				var pointX = event.pageX;
				//这里可以得到鼠标Y坐标
				var pointY = event.pageY;
				console.log("x = " + pointX + ",y = " + pointY);
				$("#detailsBox").css("top",(pointY+20)+"px");
				$("#detailsBox").css("left",(pointX+20)+"px");
				var box = $(this);
				var id = $(this).attr("orderId");
				var detailInfo = $(this).attr("detailInfo");
				if(detailInfo != ""){
					$("#detail-list").empty();
					$("#detail-list").append(detailInfo);
					$("#detailsBox").show();
					return;
				}
				$("#loading").show();
				$.ajax({
					url : contextPath + '/order',
					type : "POST",
					dataType : 'json',
					data : {
						action : 'detail',
						id:id
					},
					success : function(rs, textStatus, jqXHR) {
						if (rs.success) {
							var data = rs.data;
							var tr = "";
							for(var i = 0 ; i < data.length ; i++){
								tr += '<tr>';
								tr += '<td>'+data[i].productName+'</a></td>';
								tr += '<td><img src="' + contextPath + data[i].productImage+'" width="40px" height="40" /></td>';
								tr += '<td>'+data[i].productPrice+'</td>';
								tr += '<td>'+data[i].productCount+'</td>';
								tr += '<td>'+data[i].shopName+'</td>';
								tr += '</tr>';
							}
							box.attr("detailInfo",tr)
							$("#detail-list").empty();
							$("#detail-list").append(tr);
							$("#detailsBox").show();
						} else {
							showMessage("获取数据失败,请稍后再试");
						}
						$("#loading").hide();
					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
				});
				
			},function(){
				time = setTimeout( function(){
					$("#detailsBox").hide();
				} , 1000); 
			});
			
			//分页
			var pageList = $("#page-list");
			pageList.empty();
			pageList.append(getPageInfo20(start, total));
			$("html,body").animate({scrollTop:0},200);	
		}
		
		$("#detailsBox").hover(function(){
			clearTimeout(time); 
		},function(){
			clearTimeout(time); 
			$("#detailsBox").hide();
		});

		$("#find").click(function(){
			$("#accountMobile").val($("#mobile").val());
			getData(1);
			
		});
		$("#print").click(function(){
			var property = "";
			if($("#citys").val() == -1 || $("#citys").val() == ""|| $("#citys").val() == null){
				property = "";
			}else{
				property = "cityId=" + $("#citys").val();
			}
			if($("#areaId").val() != -1 && $("#areaId").val() != ""){
				if(property == ""){
					property = "areaId=" + $("#areaId").val();
				} else {
					property = "&areaId=" + $("#areaId").val();
				}
			}
			if($("#builderId").val() != -1 && $("#builderId").val() != ""){
				if(property == ""){
					property = "builderId=" + $("#builderId").val();
				}else{
					property += "&builderId=" + $("#builderId").val();
				}
			}
			if($("#shopId").val() != -1 && $("#shopId").val() != ""){
				if(property == ""){
					property = "shopId=" + $("#shopId").val();
				}else{
					property += "&shopId=" + $("#shopId").val();
				}
			}
			if($("#accountMobile").val() != ""){
				if(property == ""){
					property = "accountMobile=" + $("#accountMobile").val();
				}else{
					property += "&accountMobile=" + $("#accountMobile").val();
				}
			}
			var ids = "";
			$(".items").each(function(){
				if($(this).prop("checked") == true){
					ids += $(this).parent().parent().find("input").val() + ",";
				}
			});
			if(ids != ""){
				ids = ids.substring(ids,ids.length-1);
				if(property == ""){
					property = "id=in" + ids;
				}else{
					property += "&id=in" + ids;
				}
			}
			window.open( contextPath + '/order?action=exportTomorrowList&order= by orderTime desc' + (property == "" ? "" : "&" + property));
		});
		$("#printNote").click(function(){
			var property = "";
			if($("#areaId").val() == -1 || $("#areaId").val() == ""){
				property = "";
			}else{
				property = "areaId=" + $("#areaId").val();
			}
			if($("#builderId").val() != -1 && $("#builderId").val() != ""){
				if(property == ""){
					property = "builderId=" + $("#builderId").val();
				}else{
					property += "&builderId=" + $("#builderId").val();
				}
			}
			if($("#shopId").val() != -1 && $("#shopId").val() != ""){
				if(property == ""){
					property = "shopId=" + $("#shopId").val();
				}else{
					property += "&shopId=" + $("#shopId").val();
				}
			}
			if($("#accountMobile").val() != ""){
				if(property == ""){
					property = "accountMobile=" + $("#accountMobile").val();
				}else{
					property += "&accountMobile=" + $("#accountMobile").val();
				}
			}
			var ids = "";
			$(".items").each(function(){
				if($(this).prop("checked") == true){
					ids += $(this).parent().parent().find("input").val() + ",";
				}
			});
			if(ids != ""){
				ids = ids.substring(ids,ids.length-1);
				if(property == ""){
					property = "id=in" + ids;
				}else{
					property += "&id=in" + ids;
				}
			}
			window.open( contextPath + '/order?action=exportTomorrowNotes&order= by orderTime desc' + (property == "" ? "" : "&" + property));
		});
		
		
		$(".checkAll").click(function(){
			$(".items").each(function(){
				$(this).prop("checked",$(".checkAll").prop("checked"));
			});
			
		});

		function editorder(orderid){
			//查询这个orderid的信息 改他
			$("#id").val(orderid);
			var action='/order?action=get&id='+orderid;

			$.get(action,function (result) {
				result = JSON.parse(result);
				var data = result.data ;
				console.log(result);
				$("#id").val(data.id);
				$("#sendDate").val(data.sendDate);
				$("#sendTime").val(data.sendTime);
				$("#consignee").val(data.consignee);
				$("#builderName").val(data.builderName);
				$("#userMobile").val(data.userMobile);
				$("#floorNo").val(data.floorNo);
				$("#adEditBox").show();
			})

			
			//查且填充
			
			
		}

	$("#cancel").bind("click", function () {
		$("#adEditBox").hide();
		$("#id").val("");
		$("#sendDate").val("");
		$("#sendTime").val("");
		$("#consignee").val("");
		$("#builderName").val("");
		$("#userMobile").val("");
		$("#floorNo").val("");
	});

	$("#save").bind("click", function () {

		var action='/order?action=order_edit';


		if ($("#id").val() == "") {
			showMessage("id错误,请联系管理员");
			return;
		}
		if ($("#sendDate").val() == "") {
			showMessage("请输入送货日期!!!");
			return;
		}
		if ($("#sendTime").val() == "") {
			showMessage("请输入送货时间!!!");
			return;
		}
		if ($("#consignee").val() == "") {
			showMessage("请输入收货人名称!!!");
			return;
		}
		if ($("#floorNo").val() == "") {
			showMessage("请输入楼层!!!");
			return;
		}
		if ($("#builderName").val() == "") {
			showMessage("请输入送达楼宇!!!");
			return;
		}
		if ($("#userMobile").val() == "") {
			showMessage("请输入收货人手机!!!");
			return;
		}

		$("#consignee").val(encodeURI($("#consignee").val()));
		$("#builderName").val(encodeURI($("#builderName").val()));
		$("#floorNo").val(encodeURI($("#floorNo").val()));



		$("#loading").show();
		$("#adForm").ajaxSubmit({
			type: "GET",
			url: contextPath + action,
			dataType: 'json',
			success: function (data) {
				if (data.success) {
					showMessage(data.msg);

					$("#adEditBox").hide();
					$("#id").val("");
					$("#sendDate").val("");
					$("#sendTime").val("");
					$("#consignee").val("");
					$("#builderName").val("");
					$("#userMobile").val("");
					$("#floorNo").val("");
					setTimeout(function () {
						getData(1);
					}, 2000);
				} else {
					showMessage(data.msg);
				}
				$("#loading").hide();
			},
			error: function (msg) {
				$("#loading").hide();
				showMessage("操作失败");
			}
		});
	});
	function backorder(id){
		var action='/order?action=back&id='+id;
		$.get(action,function(result){
			   result = JSON.parse(result);
					if(result.success==true){
						showMessage("操作成功");
						getData(1);
					}else{
						showMegetData(1);ssage("操作失败");

					}
			})
	}

	$(function(){
		var t = setTimeout(function(){
			$("#find").click();
		},1000)
	})
	</script>
</body>
</html>